package com.gemptc.wode.service;

import java.io.IOException;
import java.io.PrintWriter;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONArray;

import com.gemptc.bean.Sciencebean;
import com.gemptc.bean.Travelsbean;
import com.gemptc.bean.UserBean;
import com.gemptc.wode.daoImp.Select_WouserImp;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

/**
 * Servlet implementation class WoGuanzhu
 */
@WebServlet("/WoGuanzhu")
public class WoGuanzhu extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public WoGuanzhu() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	/**                                                                                                                                               
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
	 *      response)
	 */
	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		PrintWriter printWriter = response.getWriter();
		String value=request.getParameter("key");
		System.out.println(value);
		String username;
		Select_WouserImp wouser=new Select_WouserImp();
		switch (Integer.parseInt(value)) {
		case 1:
			List<UserBean> UserBeanList = new ArrayList<UserBean>();
			Select_WouserImp select_WouserImp = new Select_WouserImp();
			 username = request.getParameter("username");
			int userid=wouser.selectuserid(username);
			UserBeanList = select_WouserImp.getUserbean(userid);
			JSONArray jsonArray = JSONArray.fromObject(UserBeanList);
			String result= jsonArray.toString();
			printWriter.write(result);
			System.out.println(result+"传的纸条");
			printWriter.close();
			break;
		case 2:
			List<UserBean> UserBeanList1 = new ArrayList<UserBean>();
			Select_WouserImp select_WouserImp1 = new Select_WouserImp();
			 username=request.getParameter("username");
			UserBeanList1 = select_WouserImp1.getUserBean1(username);
			Gson gson=new Gson();
			Type typeOfT=new TypeToken<List<UserBean>>(){}.getType();
			String result1=gson.toJson(UserBeanList1,typeOfT);
			printWriter.write(result1);
			break;
		case 3:
			//List<UserBean> UserBeanList2 = new ArrayList<UserBean>();
			Select_WouserImp select_WouserImp2 = new Select_WouserImp();
			String username1=request.getParameter("username");
			System.out.println(username1);
			String nicheng=request.getParameter("nicheng");
			System.out.println(nicheng);
			String xingbie=request.getParameter("sex");
			System.out.println(xingbie);
			String jianjie=request.getParameter("jianjie");
			System.out.println(jianjie);
			boolean isSucccess=select_WouserImp2.update(username1, nicheng, xingbie, jianjie);
			if (isSucccess) {
				printWriter.write("success");
			}else {
				printWriter.write("erro");
			}
			
			break;
			
		case 4:
			/*List<UserBean> UserBeanList11 = new ArrayList<UserBean>();
			Select_WouserImp select_WouserImp11 = new Select_WouserImp();
			String userid1 = request.getParameter("userid");
		
			UserBeanList11 = select_WouserImp11.getusername(Integer.parseInt(userid1));
			JSONArray jsonArray1 = JSONArray.fromObject(UserBeanList11);
			
			String result11= jsonArray1.toString();
			System.out.println("00000000000000000");
			System.out.println(result11);	
			printWriter.write(result11);
			printWriter.close();*/
			break;
		case 5:
			String user_name=request.getParameter("username");
			String fou=request.getParameter("focuse");
			System.out.println(user_name+"硬盘"+fou);
			Select_WouserImp select_WouserImp22 = new Select_WouserImp();
			boolean falg=select_WouserImp22.delect_focuse(user_name, fou);
			System.out.println(falg);
			if (falg) {
				printWriter.write("succcess");
			}else{
				printWriter.write("erro");
			}
			break;
			
		case 6:
			
			System.out.println(6);			
			List<Sciencebean> scienceList = new ArrayList<Sciencebean>();
			Select_WouserImp select_WouserImp33 = new Select_WouserImp();
			username = request.getParameter("username");
			 userid=wouser.selectuserid(username);
			
			scienceList = select_WouserImp33.seleteshoucang(userid);
			JSONArray jsonArray11 = JSONArray.fromObject(scienceList);		
			String result22= jsonArray11.toString();
			printWriter.write(result22);
			printWriter.close();
			
			break;
		case 7:
			String s_id=request.getParameter("s_id");
			String user_id=request.getParameter("user_id");
			Select_WouserImp select_WouserImp44 = new Select_WouserImp();			
			boolean falg1=select_WouserImp44.delect_shoucang(Integer.parseInt(s_id), Integer.parseInt(user_id));
			System.out.println(falg1);
			if (falg1) {
				printWriter.write("succcess");
			}else{
				printWriter.write("erro");
			}
			break;	
		case 8:
			List<Travelsbean> travelslist = new ArrayList<Travelsbean>();
			Select_WouserImp select_WouserImp55 = new Select_WouserImp();
			username = request.getParameter("username");
			 userid=wouser.selectuserid(username);
			travelslist = select_WouserImp55.seleteyoujishoucang(userid);
			JSONArray jsonArray22 = JSONArray.fromObject(travelslist);		
			String result33= jsonArray22.toString();
			printWriter.write(result33);
			printWriter.close();
			break;	
		case 9:
			List<Travelsbean> travelslist1 = new ArrayList<Travelsbean>();
			Select_WouserImp select_WouserImp66 = new Select_WouserImp();
			username = request.getParameter("username");
			 userid=wouser.selectuserid(username);
			travelslist1 = select_WouserImp66.seletemyouji(userid);
			JSONArray jsonArray33 = JSONArray.fromObject(travelslist1);		
			String result44= jsonArray33.toString();
			printWriter.write(result44);
			printWriter.close();
			break;
			
		case 10:
			String t_id=request.getParameter("t_id");
			String user_id1=request.getParameter("user_id");
			System.out.println(t_id);
			System.out.println(user_id1);
			Select_WouserImp d1 = new Select_WouserImp();
			
			boolean fg=d1.delect_youji(Integer.parseInt(t_id), Integer.parseInt(user_id1));
			System.out.println(fg);
			if (fg) {
				printWriter.write("succcess");
			}else{
				printWriter.write("erro");
			}
			break;	
		default:
			break;
		}
		
	}

}
